package com.healthcloud.service.impl;

import java.util.ArrayList;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.healthcloud.dao.AppVersionControllMapper;
import com.healthcloud.entity.AppVersion;
import com.healthcloud.service.AppVersionService;

/**
 * Created by XYC on 2015/7/28.
 */
@Service
public class AppVersionServiceImpl implements AppVersionService {

    @Autowired
    private AppVersionControllMapper appVersionControllMapper;

    @Override
    public ArrayList<AppVersion> findByAllAppVersionWithMobileOSWithoutPage(AppVersion appVersion) {
        return appVersionControllMapper.findByMobileOSWithOutPage(appVersion);
    }

    @Override
    public AppVersion findListAppVersionWithMobileOS(AppVersion appVersion) {
        AppVersion appVersion1 = new AppVersion();
        appVersion1.setMobileOS(appVersion.getMobileOS());
        ArrayList<AppVersion> appVersions = findByAllAppVersionWithMobileOSWithoutPage(appVersion1);

        return appVersions.get(appVersions.size() - 1);
    }

    @Override
    public AppVersion phoneAppNeedData(AppVersion appVersion) {
        AppVersion appVersion1 = new AppVersion();
        appVersion1.setAppCode(appVersion.getAppCode());
        appVersion1.setAppName(appVersion.getAppName());
        appVersion1.setAppAddress(appVersion.getAppAddress());
        appVersion1.setVersion(appVersion.getAppAddress());
        return appVersion1;
    }

    @Override
    public HashMap<String, Object> phoneAppNeedHashMap(AppVersion appVersion) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("appCode",appVersion.getAppCode());
        hashMap.put("appName",appVersion.getAppName());
        hashMap.put("appAddress",appVersion.getAppAddress());
        hashMap.put("version",appVersion.getVersion());
        return hashMap;
    }


    @Override
    public ArrayList<AppVersion> findByAppCode(AppVersion appVersion) {
        AppVersion appVersion1 = new AppVersion();
        appVersion1.setAppCode(appVersion.getAppCode());
        return findByAllAppVersionWithMobileOSWithoutPage(appVersion1);
    }

    @Override
    public AppVersion changeTimeShow(AppVersion appVersion) {
        appVersion.setReleaseTimeOfString(appVersion.DateTimeTransformString(appVersion.getReleaseTime()));
        appVersion.setCreatedTimeOfString(appVersion.DateTimeTransformString(appVersion.getCreatedTime()));
        appVersion.setUpdatedTimeOfString(appVersion.DateTimeTransformString(appVersion.getUpdatedTime()));
        appVersion.setReleaseTime(null);
        appVersion.setCreatedTime(null);
        appVersion.setUpdatedTime(null);
        return appVersion;
    }

/*    private ArrayList<AppVersion> findByEntity(AppVersion appVersion){

        return (ArrayList<AppVersion>) appVersionControllMapper.findByEntityAll(appVersion);
    }*/
}
